﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CH.TestData.Common;
using System.Windows.Forms;

namespace CH.TestData.Provider
{

     [DataTypeName("名字")]
    public class NameProvider : IDataProvider
    {
        private bool? isMale;
        private string columnName;
        public string GetNextValue()
        {
            return "N'" + NameHelper.GetName(this.isMale) + "'";
        }

        public void SetDataSource(FlowLayoutPanel flp)
        {
            TextBox txtColumnName = flp.Controls.Find("txtColumnName", false).First() as TextBox;
            this.columnName = txtColumnName.Text;
            ComboBox cbType = flp.Controls.Find("cbType", true).First() as ComboBox;
            if (cbType.SelectedValue.ToString() == "MaleAndFeMale")
            {
                isMale = null;
            }
            else
            {
                this.isMale = cbType.SelectedValue.ToString() == "Male" ? true : false;
            }
        }
       

        public void CreateOption(FlowLayoutPanel flp)
        {
            Label lbls = new Label();
            lbls.Text = "性别";
            lbls.Width = 30;
            lbls.Margin = new Padding(0, 7, 0, 0);
            flp.Controls.Add(lbls);

            ComboBox cbType = new ComboBox();
            cbType.DataSource = new List<KeyValuePair<string, string>> 
            {
                new KeyValuePair<string,string>("Male", "男"),
                new KeyValuePair<string,string>("FeMale", "女"),
                new KeyValuePair<string,string>("MaleAndFeMale", "男和女")
            };
            cbType.DisplayMember = "Value";
            cbType.ValueMember = "Key";
            cbType.Width = 100;
            cbType.Name = "cbType";
            cbType.DropDownStyle = ComboBoxStyle.DropDownList;
            flp.Controls.Add(cbType);
        }
    }
}
